import { defineStore } from 'pinia'
import { reqCatvInfo, reqRecommendInfo } from '../api/api1/home'
import type { data, recommendInfoStoreModel, categoryHotSellStoreModule } from '../api/api1/home'

// reqCatvInfo
export const useHomeStore = defineStore('home', {
  state(): any {
    return {
      // 推荐数据   这里全是你的推荐数据吗 是  我看看老师的代码

      categoryHotSellModuleInfo: {},
      kingKongModuleInfo: {},
      policyDescListInfo: [],
      bigPromotionModuleInfo: {},
      sceneLightShoppingGuideModuleInfo: [],
      focusListInfo: [],
      categoryItemListInfo: [],
      categoryListInfo: [],
      currentCategoryInfo: []


    }
  },
  actions: {
    // 推荐数据
    async getRecommendInfo() {
      const res: any = await reqRecommendInfo()
      // console.log('pinia', res.data)
      this.categoryHotSellModuleInfo = res.data.categoryHotSellModule
      this.kingKongModuleInfo = res.data.kingKongModule
      this.policyDescListInfo = res.data.policyDescList
      this.bigPromotionModuleInfo = res.data.bigPromotionModule
      this.sceneLightShoppingGuideModuleInfo = res.data.sceneLightShoppingGuideModule
      this.focusListInfo = res.data.focusList

    },
    // 频道数据

    async getCatvInfo(id: number) {
      const res = await reqCatvInfo(id)
      console.log('pind', res)
      this.categoryItemListInfo = res.categoryItemList
      this.categoryListInfo = res.categoryList
      this.currentCategoryInfo = res.currentCategory

    }

  },
  getters: {
    // 推荐数据
    categoryList(state) {
      return state.categoryHotSellModuleInfo.categoryList
    },
    kingKongList(state) {
      return state.kingKongModuleInfo.kingKongList
    },
    cellsList(state) {
      const cell = (state.bigPromotionModuleInfo?.floorList || []).map((item: any) => {
        // console.log('cells', item)
        return item.cells

      });
      // console.log('ce', cell)
      return cell
    },
    styleBanner(state) {
      return state.sceneLightShoppingGuideModuleInfo[0]?.styleBanner
    },
    styleItem(state) {
      return state.sceneLightShoppingGuideModuleInfo[1]?.styleItem
    }
  }
})